package cn.com.controller;

import cn.com.domain.dto.NoticeDTO;
import cn.com.mapper.NoticeMapper;
import cn.com.service.NoticeService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import cn.com.response.BaseResponse;

/**
 * 公告信息
 *
 * @Author CRL
 * @Date 2021/4/13 23:32
 */
@RestController
@Slf4j
@RequestMapping("/api/v1/notice")
public class NoticeController {

    @Autowired
    NoticeService noticeService;

    @Autowired
    NoticeMapper noticeMapper;

    @PostMapping
    public BaseResponse creat(@RequestBody(required = false) NoticeDTO requestDto) {
        return noticeService.saveNotice(requestDto);
    }

    @DeleteMapping("/{id}")
    public BaseResponse delete(@PathVariable("id") String id) {
        return noticeService.deleteNotice(id);
    }

    @PutMapping("/{id}")
    public BaseResponse update(@PathVariable("id") String id, @RequestBody(required = false) NoticeDTO requestDto) {
        return noticeService.updateNotice(id, requestDto);
    }

    @PostMapping("/query")
    public BaseResponse query(@RequestBody(required = false) NoticeDTO requestDto) {
        return noticeService.queryNotice(requestDto);
    }

    @GetMapping("/{id}")
    public BaseResponse findOneById(@PathVariable("id") String id) {
        return noticeService.findOneById(id);
    }

}
